package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IWgtsTaskDetailsActivityModel;
import com.wgts.wgts.mvp.presenter.IWgtsTaskDetailsActivityPresenter;
import com.wgts.wgts.mvp.view.IWgtsTaskDetailsActivityView;
import com.wgts.wgts.mvp.view.activity.tasklobby.WgtsTaskDetailsActivity;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.CurrentEntity;
import com.wgts.wgts.netmodle.resp.TaskDetailEntity;

/*
 *
 *
 */public class WgtsTaskDetailsActivityPresenter implements IWgtsTaskDetailsActivityPresenter {
     private IWgtsTaskDetailsActivityView view;
     private IWgtsTaskDetailsActivityModel model;

    public WgtsTaskDetailsActivityPresenter(IWgtsTaskDetailsActivityView view, IWgtsTaskDetailsActivityModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void initDate(Integer taskId) {
        model.initDate(taskId, new HttpResultSubscriber<TaskDetailEntity>() {
            @Override
            public void onSuccess(TaskDetailEntity entity) {
                view.initDate(entity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void joinTaskDetailsDate(Integer userTaskId) {
        model.joinTaskDetails(userTaskId, new HttpResultSubscriber<TaskDetailEntity>() {
            @Override
            public void onSuccess(TaskDetailEntity entity) {
                view.joinTaskDetail(entity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void issueTask(Integer taskId, String taskCode, String taskUrl) {
        model.issueTask(taskId, taskCode, taskUrl, new HttpResultSubscriber<Integer>() {
            @Override
            public void onSuccess(Integer currentEntity) {
                view.issueResult(currentEntity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void vertifyTask(Integer userTaskId) {
        model.vertifyTask(userTaskId, new HttpResultSubscriber<CurrentEntity>() {
            @Override
            public void onSuccess(CurrentEntity currentEntity) {
                view.vertifyTask();
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(WgtsTaskDetailsActivity.VERTIFY_TASK, msg);
            }
        });
    }
}
